package com.utf999.qiangmanger.entity.orm;

import java.util.Date;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import com.utf999.qiangmanger.entity.UUIDEntity;

/**
 * 工单信息数据表
 * @author yinwenjie
 */
@Entity
@Table(name="O_Orderinfo")
public class OrderInfoEntity extends UUIDEntity {
	/**
	 * 
	 */
	private static final long serialVersionUID = -6345506253275994901L;
	
	/**
	 * 房间编号
	 */
	@Column(name="roomNo" , length=10 , nullable=false)
	private String roomNo;
	
	/**
	 * 工单对应的店面信息
	 */
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="storefront" , nullable=false)
	private StorefrontEntity storefront;
	
	/**
	 * 工单对应的公司信息（冗余信息，以便查询）
	 */
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="company" , nullable=false)
	private CompanyEntity company;
	
	/**
	 * 工单类型
	 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name="orderType" , nullable=false)
	private OrderTypeEntity orderType;
	
	/**
	 * 订单状态
	 * 0：作废（撤回）
	 * 1：正在抢单
	 * 2：已派单
	 * 3、已完成（服务完成）
	 * 4、已核算（已归档）
	 */
	@Column(name="orderStatus" , nullable=false)
	private Integer orderStatus = 0;
	
	/**
	 * 这类工单的标准处理时长 （单位秒）。
	 */
	@Column(name="duration" , nullable=false)
	private Integer duration = 0;
	
	/**
	 * 工单所获得的积分
	 */
	@Column(name="integral" , nullable=false)
	private Integer integral = 0;
	
	/**
	 * 核算后这个工单服务者实际获取的积分
	 */
	@Column(name="realIntegral" , nullable=true)
	private Integer realIntegral = 0;
	
	/**
	 * 专门为消费类型单准备的“消费总金额”
	 */
	@Column(name="totalAmount" , nullable=true)
	private Float totalAmount = 0.0f;
	
	/**
	 * 核算后的这个“消费工单”实际的付款总金额
	 */
	@Column(name="realTotalAmount" , nullable=true)
	private Float realTotalAmount = 0.0f;
	
	/**
	 * 当一张工单为消费单时（即工单类型诶0001），这个工单对应的商品可能需要经过超市配货。<br>
	 * 这个字段用于表示超市的配货状态：
	 * 0：未配货
	 * 1：已完成配货
	 */
	@Column(name="pickingStatus" , nullable=false)
	private Integer pickingStatus = 0;
	
	/**
	 * 分配模式，工单的分配模式<br>
	 * 默认为：抢单模式
	 * 1、抢单模式
	 * 2、指派模式
	 */
	@Column(name="orderMode" , nullable=false)
	private Integer orderMode = 1;
	
	/**
	 * 工单任务说明
	 */
	@Column(name="remark" , length=5000 , nullable=false)
	private String remark = "";
	
	/**
	 * 负责处理工单的服务员
	 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name="waiter" , nullable=true)
	private StoreUserEntity waiter;
	
	/**
	 * 工单核算者
	 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name="accountAdmin" , nullable=true)
	private AdminUserEntity accountAdmin;
	
	/**
	 * 工单的创建时间
	 */
	@Column(name="createTime" , nullable=false)
	private Date createTime = new Date();
	
	/**
	 * 工单的指派时间（派单到具体某个人的时间）
	 */
	@Column(name="appointeTime" , nullable=true)
	private Date appointeTime;
	
	/**
	 * 工单完成服务的时间
	 */
	@Column(name="serviceOverTime" , nullable=true)
	private Date serviceOverTime;
	
	/**
	 * 工单的归档时间
	 */
	@Column(name="filingTime" , nullable=true)
	private Date filingTime;
	
	/**
	 * 映射了“抢单”模式下，工单所分配到的用户组编号信息
	 */
	@ManyToMany(fetch=FetchType.LAZY)
	@JoinTable(name="O_OrderinfoGroupMapping" , joinColumns={@JoinColumn(name="ORDERINFO_ID")} , inverseJoinColumns={@JoinColumn(name="STOREGROUP_ID")})
	private Set<StoreUserGroupEntity> groups;
	
	/**
	 * 该工单如果是“消费工单”，那么对应的商品信息使用这个集合属性进行说明
	 */
	@OneToMany(fetch=FetchType.LAZY , mappedBy="orderInfo")
	private Set<OrderInfoCommodityEntity> commoditys;
	
	public String getRoomNo() {
		return roomNo;
	}

	public void setRoomNo(String roomNo) {
		this.roomNo = roomNo;
	}

	public OrderTypeEntity getOrderType() {
		return orderType;
	}

	public void setOrderType(OrderTypeEntity orderType) {
		this.orderType = orderType;
	}

	public Integer getOrderStatus() {
		return orderStatus;
	}

	public void setOrderStatus(Integer orderStatus) {
		this.orderStatus = orderStatus;
	}

	public Integer getIntegral() {
		return integral;
	}

	public void setIntegral(Integer integral) {
		this.integral = integral;
	}

	public Float getTotalAmount() {
		return totalAmount;
	}

	public void setTotalAmount(Float totalAmount) {
		this.totalAmount = totalAmount;
	}

	public Integer getOrderMode() {
		return orderMode;
	}

	public void setOrderMode(Integer orderMode) {
		this.orderMode = orderMode;
	}

	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

	public StoreUserEntity getWaiter() {
		return waiter;
	}

	public void setWaiter(StoreUserEntity waiter) {
		this.waiter = waiter;
	}

	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	public Date getAppointeTime() {
		return appointeTime;
	}

	public void setAppointeTime(Date appointeTime) {
		this.appointeTime = appointeTime;
	}

	public Date getFilingTime() {
		return filingTime;
	}

	public void setFilingTime(Date filingTime) {
		this.filingTime = filingTime;
	}

	public Date getServiceOverTime() {
		return serviceOverTime;
	}

	public void setServiceOverTime(Date serviceOverTime) {
		this.serviceOverTime = serviceOverTime;
	}

	public Integer getDuration() {
		return duration;
	}

	public void setDuration(Integer duration) {
		this.duration = duration;
	}

	public Integer getPickingStatus() {
		return pickingStatus;
	}

	public void setPickingStatus(Integer pickingStatus) {
		this.pickingStatus = pickingStatus;
	}

	public Set<StoreUserGroupEntity> getGroups() {
		return groups;
	}

	public void setGroups(Set<StoreUserGroupEntity> groups) {
		this.groups = groups;
	}

	public StorefrontEntity getStorefront() {
		return storefront;
	}

	public void setStorefront(StorefrontEntity storefront) {
		this.storefront = storefront;
	}

	public CompanyEntity getCompany() {
		return company;
	}

	public void setCompany(CompanyEntity company) {
		this.company = company;
	}

	public Set<OrderInfoCommodityEntity> getCommoditys() {
		return commoditys;
	}

	public void setCommoditys(Set<OrderInfoCommodityEntity> commoditys) {
		this.commoditys = commoditys;
	}
	
	public Integer getRealIntegral() {
		return realIntegral;
	}

	public void setRealIntegral(Integer realIntegral) {
		this.realIntegral = realIntegral;
	}

	public Float getRealTotalAmount() {
		return realTotalAmount;
	}

	public void setRealTotalAmount(Float realTotalAmount) {
		this.realTotalAmount = realTotalAmount;
	}

	public AdminUserEntity getAccountAdmin() {
		return accountAdmin;
	}

	public void setAccountAdmin(AdminUserEntity accountAdmin) {
		this.accountAdmin = accountAdmin;
	}

	/* (non-Javadoc)
	 * @see com.utf999.qiangmanger.entity.UUIDEntity#getUniqueKey()
	 */
	@Override
	public String getUniqueKey() {
		return "uid";
	}
}